<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .front {
            color: transparent;
        }
    </style>
</head>

<body>
    <script>

        // while实现1-100相加求和
        var num = 1;
        var i = 1;
        var sum = 0;
        while (i <= 100) {
            sum += num;
            num++;
            i++;
        }
        document.write('1-100相加求和为：' + sum + '<br>');
        // var i = 1, sum = 0;
        // while (i <= 100) {
        //     // if (i == 100) {
        //     //     document.write(i + '=');
        //     // } else {
        //     //     document.write(i + '+');
        //     // }
        //     // i == 100 ? document.write(i + '=') : document.write(i + '+');
        //     var unit = i == 100 ? ' = ' : ' + ';
        //     document.write(i + unit);
        //     sum = sum + i;
        //     i++;
        // }
        // // console.log(sum);
        // document.write(sum);
        document.write('<br>');

        // while do...while验证用户名和密码

        do {
            var user = parseInt(prompt('请输入用户名（1）'));
            var psd = parseInt(prompt('请输入密码（1）'));
            while (user != 1 && psd == 1) {
                alert('用户名错误');
                break;
            }
            while (user == 1 && psd != 1) {
                alert('密码错误');
                break;
            }
            while (user == 1 && psd == 1) {
                alert('登录成功');
                break;
            }
            while (user != 1 && psd != 1) {
                alert('用户名与密码错误');
                break;
            }

        } while (user != 1 || psd != 1)



        // 打印菱形、三角形
        for (var i = 1; i <= 5; i++) { // 外层循环负责打印五行

            for (var front = 5 - i; front >= 1; front--) {
                document.write('<span class="front">*</span>');
            }
            for (var j = 1; j <= 2 * i - 1; j++) { // 里层循环负责一行打印几个*
                document.write('*');
            }
            document.write('<br>');
        }
        document.write('<br>');


        for (var i = 1; i <= 9; i++) { // 外层循环负责打印五行
            if (i <= 5) {
                for (var front = 1; front <= 5 - i; front++) {
                    document.write('<span class="front">*</span>');
                }
                for (var j = 1; j <= 2 * i - 1; j++) { // 里层循环负责一行打印几个*
                    document.write('*');
                }

            } else {//6 7 8 9
                for (var front = 1; front <= i - 5; front++) {
                    document.write('<span class="front">*</span>');
                }
                for (var j = (10 - i) * 2 - 1; j > 0; j--) { // 里层循环负责一行打印几个*
                    document.write('*');
                }

            }
            document.write('<br>');
        }
        document.write('<br>');


        // 一百个和尚分一百个馒头，大和尚一人分三个，小和尚三人分一个，正好分完。问大、小和尚各几人？
        for (var big = 1; big <= 100; big++) {
            var small = 100 - big;
            if (big * 3 + small / 3 == 100) {
                document.write('大和尚：' + big + ',小和尚：' + small + '<br>')
            }

        }
        document.write('<br>');


        // - 公鸡一个五块钱，母鸡一个三块钱，小鸡三个一块钱，现在要用一百块钱买一百只鸡，问公鸡、母鸡、小鸡各多少只？
        for (var male = 0; male <= 20; male++) {
            for (var female = 0; female <= 33; female++) {
                var small = 100 - male - female;
                if (male * 5 + female * 3 + small / 3 == 100) {
                    document.write('公鸡：' + male + ', 母鸡：' + female + ', 小鸡：' + small + '<br>')
                }
            }
        }
        document.write('<br>');


        // 红白球共25个，白黑球共31个，红黑球共28个，求三种球各有多少？求红白黑球的个数
        // for (var red = 0; red <= 25; red++) {
        //     for (var white = 0; white <= 25; white++) {
        //         for (var blank = 0; blank <= 28; blank++) {
        //             if (red + white == 25 && white + blank == 31 && red + blank == 28) {
        //                 document.write('红球：' + red + ' ,白球：' + white + ' ,黑球：' + blank + '<br>')
        //             }
        //         }
        //     }
        // }
        for (var red = 0; red <= 25; red++) {
            var white = 25 - red,
                black = 28 - red;
            if (white + black == 31) {
                document.write('红球的数量是：' + red + '， 白球的数量是：' + white + '， 黑球的数量是：' + black + ' <br>');
            }
        }
    </script>
</body>

</html>